package leet.ku._303;

public class NumArray {
	
	private int[] sums;

    public NumArray(int[] nums) {
        sums = new int[nums.length + 1];
        for (int i = 0; i < nums.length; i++)
        	sums[i + 1] = sums[i] + nums[i];
    }

    public int sumRange(int i, int j) {
    	if (i > j || i >= sums.length - 1)
    		return 0;
    	if (j >= sums.length - 1)
    		j = sums.length - 2;
    	if (i < 0)
    		i = 0;
        return sums[j + 1] - sums[i];
    }
}